<template>
	<view class="myOrderBox">
        
		<view class="orderTitle">
			<view :class="[titleFlag==0?'active':'titleItem']" @click="unpaidBtn(0)">
				即时订单
			</view>
			<view :class="[titleFlag==1?'active':'titleItem']" @click="unpaidBtn(1)">
				预约订单
			</view>
		
		</view>
		
			<view class="orderItem bgWhite plr14 ptb13  mlr15 mt18 radius6  " v-for="(item,index) in orderList" :key="n"
				@click="toMain(item)">
				<view class="justify-between" style="position: relative;">
					<image style="width: 260rpx;height: 320rpx;"  :src="item.image" mode=""></image>
					<view class="flex-col orderright justify-between ">
						<view class="orderName  align-center ">{{item.name}} <text class="mlr10">({{item.type_name}})</text>   <uv-icon color="#01C588" name="star-fill"></uv-icon> {{item.eval}} </view>
						<view class="">
							{{item.shop_name}} 
						</view>
					    <view class="justify-start align-center">
					        <text class="mr15">年龄：{{item.age}}岁</text>
					        <text>  学历：{{item.xueli}}</text>
					    </view>
						<view class="">
							段位：{{item.level||""}}段
						</view>
					    <view class="justify-between align-center" v-if="item.time_arr">
					        <view class="remark clamp2" style="width: 100%;">
					            时间：<text class="mr20" v-for="(i,n) in JSON.parse(item.time_arr)">{{i}}</text> 
					        </view>
					            
					    </view>
					</view>
					<view class="tagStatus">
					    <text class="point"></text>
					    {{item.status==1?"工作中":'空闲' }}
					</view>
				</view>
                <block v-if="titleFlag==1">
					<uv-line margin="30rpx 0"></uv-line>
					<view  class="justify-end" @click="cancel(item)">
						<view class="apply"> 取消预约 </view>
					</view>
                </block>    
					
			</view>
		
		<view class="" v-if="orderList.length==0">
			<uv-empty mode="data" icon="https://cdn.uviewui.com/uview/empty/data.png"></uv-empty>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				titleFlag: 0,
				orderList: [{

				}],
				allCarData: [],
				orderItem: {},
				imgList: [],
				user_id: uni.getStorageSync('userId'),
				page: 1

			};
		},
		onLoad() {
			this.getOrder()
		},
		onShow() {
			// if (!uni.getStorageSync('logintoken')) {
			// 	uni.reLaunch({
			// 		url: '/pages/login/login'
			// 	})
			// 	return
			// }
			// this.getOrder()
		},
		methods: {
			formateTime(data) {
				return this.$utils.formatDateTime(data)
			},
			//立即支付
			payBtn() {
				uni.navigateTo({
					url: '/pages/mine/payment'
				})
			},
			//更多照片

			//验证车弹窗关闭
			carImgClose() {
				this.$refs.checkCar.close();
			},
			async getOrder() {
				let data;
            
				if (this.titleFlag == 0) {
					data = await this.$api.myShopAssistantOrder({
						page: this.page
					})
				} else if (this.titleFlag == 1) {
					
                   data=await  this.$api.yuyueAssistantOrder({page:this.page})
                  
				} 
				

				this.orderList = data.list
			},

			goBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			//待支付按钮
			unpaidBtn(type) {
				this.page = 1
				this.orderList = []
				this.titleFlag = type
				this.getOrder()
			},

			//合同按钮
			contractBtn() {
				this.$refs.dzContract.open();
			},
			//合同弹窗关闭
			contractClose() {
				this.$refs.dzContract.close();
			},
			//全部车辆弹窗
			allCarBtn(data) {
				this.orderItem = data
				this.allCarData = JSON.parse(data.car_arr)
				this.$refs.carModal.open();
			},
			//车辆弹窗关闭
			carClose() {
				this.$refs.carModal.close();
			},
			async showAllImg(item) {
				const {
					data
				} = await this.$api.cartImage({
					order_id: item.id
				})
				console.log(data)
				this.imgList = data.list
				this.$refs.checkCar.open();
			},
			async getImglist(id) {
				const {
					data
				} = await this.$api.cartImage({
					order_id: id
				})

				return data.list
			},
			toMain(item) {
                console.log(item)
				uni.navigateTo({
					url: '/pages/userMain/index?id=' + item.id
				})
			},
			submitpz(id) {
				uni.navigateTo({
					url: '/pages/pay/index?id=' + id
				})
			},
			toshop(i) {
				uni.navigateTo({
					url: '/pages/store/index?shop_id=' + i.shop_id
				})
			},
            cancel(item){
                
                let vm =this
                    uni.showModal({
                        title:'提示',
                        content:'确定要取消预约吗?',
                        success:function(res){
                            if(res.confirm){
                                vm.$api.cancelShopAssistant({
                                	
                                	id:item.id
                                }).then(res=>{
                                	uni.showToast({
                                		title:'取消成功',
                                		icon:'none'
                                	})
                                	vm.getOrder()
                                })
                            }
                        }
                    })
            }
		}
	}
</script>

<style lang="scss" scoped>
	.myOrderBox {
		min-height: 100vh;
		position: relative;
		background-color: RGBA(245, 245, 245, 1);

		

	}

	.submitPz {
		width: 165rpx;
		height: 54rpx;
		background: #434343;
		border-radius: 6rpx;
		font-size: 24rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 54rpx;
	}

	.artItem {
		box-shadow: 0rpx 0rpx 12rpx 0rpx rgba(0, 0, 0, 0.0612);
		background-color: #fff;
		font-size: 24rpx;
		color: #9F9F9F;
		margin-bottom: 36rpx;

		image {
			width: 132rpx;
			height: 132rpx;
			border-radius: 10rpx;

		}

		.right {

			font-size: 28rpx;
			color: #666666;

		}

		.title {
			font-weight: bold;
			font-size: 30rpx;
			color: #111111;
		}
	}

	.price {
		font-weight: 400;
		font-size: 24rpx;
		color: #666666;
		width: calc(100% - 500rpx);

		.money {
			font-weight: bold;
			font-size: 28rpx;
			color: #222222;

		}
	}
	.orderItem {
		font-size: 24rpx;
		color: #333;
		
		image {
			width: 205rpx;
			height: 205rpx;
			border-radius: 15rpx;
			margin-right: 20rpx;
	
		}
	
		.orderright {
			width: 376rpx;
	
			.orderName {
				font-weight: bold;
				font-size: 26rpx;
				color: #1C1C1C;
			}
	
			.price {
				color: #2CC6A1;
				font-size: 26rpx;
			}
		}
	
		.apply {
			width: 140rpx;
			height: 48rpx;
			background: #00C584;
			
			
			border-radius: 60rpx;
			line-height: 54rpx;
			text-align: center;
			font-size: 28rpx;
			color: #FFFFFF;
		}
	}
	.tagStatus{
	    align-items: center;
	    display: flex;
	    font-weight: 400;
	    font-size: 20rpx;
	    padding: 6rpx 9rpx 6rpx 15rpx;
	    background: rgba(255,255,255,0.7);
	    justify-content: center;
	    width: auto;
	        display: inline-flex;
	        left: 16rpx;
	        position: absolute;
	        border-radius: 15rpx ;
	       bottom: 20rpx;
	        color: #fff;
	    .point{
	        width: 8rpx;
	        height: 8rpx;
	        border: 1px solid #FFFFFF;
	        background-color: #25CE87;
	        border-radius: 50%;
	        display: inline-block;
	        margin-right: 4rpx;
	    }
	}
</style>